package com.tian.code.tool;

import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;

/**
 * 获取当前用户所有表名
 * 
 * @author xiecs
 * 
 */
public class GetAllTableName {

	private String fileName = "E:\\dust\\CodeTool\\config\\tableName.txt";

	private JdbcTemplate jdbcTemplate;

	public GetAllTableName() {
		ApplicationContext context = new ClassPathXmlApplicationContext("\\cfg\\spring.xml");
		jdbcTemplate = (JdbcTemplate) context.getBean("jdbcTemplate");
	}

	public void strat() {
		PrintWriter pw = null;
		try {
			pw = new PrintWriter(new FileWriter(new File(fileName)));
			List<Map<String, Object>> r = jdbcTemplate.queryForList("SELECT table_name FROM user_tables");
			for (Map<String, Object> m : r) {
				pw.println(m.get("table_name"));
			}
			pw.flush();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		new GetAllTableName().strat();
	}

}
